package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.req.StatisticsOneReq;
import com.ruoyi.system.domain.req.StatisticsThreeReq;
import com.ruoyi.system.service.TongJiService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/system/tongJi")
public class TongJiController extends BaseController {

    @Resource
    private TongJiService tongJiService;

    @GetMapping("/statisticsOne")
    @Anonymous
    private AjaxResult statisticsOne(StatisticsOneReq req) {
        if (req.getTypeIdListStr() != null && !"".equals(req.getTypeIdListStr())) {
            List<Long> typeIdList = new ArrayList<>();
            Arrays.asList(req.getTypeIdListStr().split(",")).forEach(item -> {
                typeIdList.add(Long.parseLong(item));
            });
            req.setTypeIdList(typeIdList);
        }
        return AjaxResult.success(tongJiService.statisticsOne(req));
    }

    @GetMapping("/statisticsThree")
    @Anonymous
    private AjaxResult statisticsThree(StatisticsThreeReq req) {
        if (req.getDeptIdListStr() != null && !"".equals(req.getDeptIdListStr())) {
            List<Long> deptIdList = new ArrayList<>();
            Arrays.asList(req.getDeptIdListStr().split(",")).forEach(item -> {
                deptIdList.add(Long.parseLong(item));
            });
            req.setDeptIdList(deptIdList);
        }
        return AjaxResult.success(tongJiService.statisticsThree(req));
    }

}
